package miiteen.hb.fw.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import miiteen.core.result.ResultMessage;
import miiteen.core.result.ResultMessageTool;
import miiteen.customsportal.basic.service.HistoryViewService;
import miiteen.data.beans.PageBounds;
import miiteen.hb.fw.beans.FwInfo;
import miiteen.hb.fw.service.FwInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("发文")
@RequestMapping("/hb/fw")
@RestController
@CrossOrigin
public class FwInfoController {

    @Autowired
    private FwInfoService fwInfoService;

    @Autowired
    private HistoryViewService historyViewService;
    @ApiOperation("兰关发文")
    @GetMapping("/lgfw")
    public ResultMessage<List<FwInfo>> lgfw(@RequestParam int pageSize, @RequestParam int pageNum, String subject) {
        //获取查询条件
        PageBounds pageBounds = new PageBounds();
        pageBounds.setPageNum(pageNum);
        pageBounds.setPageSize(pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("typeId", "FILE_ZG");
        map.put("orderby", "COMPLATE_DATE desc");
        map.put("isPufa", 1);
        if (StringUtils.isNotBlank(subject)) {
            map.put("subject", "%" + subject + "%");
        }
        //查询数据
        List<FwInfo> list = fwInfoService.findListByMap(map, pageBounds);
        historyViewService.fillVisitCount(list);
        if (list != null && list.size() > 0) {
            return ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), list);
        } else {
            return ResultMessageTool.Success("0", new ArrayList<>());
        }
    }

    @ApiOperation("会议纪要")
    @GetMapping("/hyjy")
    public ResultMessage<List<FwInfo>> hyjy(@RequestParam int pageSize, @RequestParam int pageNum, String subject) {
        //获取查询条件
        PageBounds pageBounds = new PageBounds();
        pageBounds.setPageNum(pageNum);
        pageBounds.setPageSize(pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("typeId", "FILE_ZG_JIYAO");
        map.put("orderby", "COMPLATE_DATE desc");
        map.put("isPufa", 1);
        if (StringUtils.isNotBlank(subject)) {
            map.put("subject", "%" + subject + "%");
        }
        //查询数据
        List<FwInfo> list = fwInfoService.findListByMap(map, pageBounds);
        historyViewService.fillVisitCount(list);
        if (list != null && list.size() > 0) {
            return ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), list);
        } else {
            return ResultMessageTool.Success("0", new ArrayList<>());
        }
    }
}